package com.cskaoyan.service.impl;

import com.cskaoyan.bean.pojo.MallOrderGoods;
import com.cskaoyan.bean.pojo.MallUser;
import com.cskaoyan.bean.pojo.MallUserExample;
import com.cskaoyan.bean.vo.StatBaseVO;
import com.cskaoyan.bean.vo.StatGoodsVO;
import com.cskaoyan.bean.vo.StatOrderVO;
import com.cskaoyan.bean.vo.StatUserVO;
import com.cskaoyan.mapper.MallOrderGoodsMapper;
import com.cskaoyan.mapper.MallOrderMapper;
import com.cskaoyan.mapper.MallUserMapper;
import com.cskaoyan.service.StatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: zoey-zhu
 * @description: 统计报表: admin/stat
 * @Date: 10:46 2021/7/9
 */
@Service
public class StatServiceImpl implements StatService {

    @Autowired
    MallUserMapper mallUserMapper;

    @Autowired
    MallOrderMapper mallOrderMapper;

    @Autowired
    MallOrderGoodsMapper mallOrderGoodsMapper;

    /**
     * @Author: zoey-zhu
     * @description: 用户统计(GET): 日期、用户增长数
     * @Date 10:53 2021/7/9
     * url: http://182.92.235.201:8083/admin/stat/user
     */
    @Override
    public StatBaseVO<StatUserVO> statUser() {

        List<StatUserVO> rows = mallUserMapper.selectUserGroupByDay();

        String[] columns = {"day", "users"};
        StatBaseVO<StatUserVO> statBaseVO = new StatBaseVO<>(columns, rows);
        return statBaseVO;
    }

    /**
     * @Author: zoey-zhu
     * @description: 订单统计(GET): 日期、订单量、下单用户、订单总额、客单价
     * @Date 10:53 2021/7/9
     * url: http://182.92.235.201:8083/admin/stat/order
     */
    @Override
    public StatBaseVO<StatOrderVO> statOrder() {

        List<StatOrderVO> rows = mallUserMapper.selectOrderGroupByDay();

        String[] columns = {"day", "orders", "customers", "amount", "pcr"};
        StatBaseVO<StatOrderVO> statBaseVO = new StatBaseVO<>(columns, rows);
        return statBaseVO;
    }

    /**
     * @Author: zoey-zhu
     * @description: 商品统计(GET): 日期、订单量、下单货品数量、下单货品总额
     * @Date 10:53 2021/7/9
     * url: http://182.92.235.201:8083/admin/stat/goods
     */
    @Override
    public StatBaseVO<StatGoodsVO> statGoods() {

        List<StatGoodsVO> rows = mallUserMapper.selectGoodsGroupByDay();

        String[] columns = {"day", "orders", "products", "amount"};
        StatBaseVO<StatGoodsVO> statBaseVO = new StatBaseVO<>(columns, rows);
        return statBaseVO;
    }
}
